﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CoursesControl.ascx.cs" Inherits="AcademicPlanner.Presentation.Views.Shared.CoursesControl" %>

<%@ Import Namespace="AcademicPlanner.Framework.Helpers" %>
<%@ Import Namespace="AcademicPlanner.Presentation" %>
<%@ Import Namespace="AcademicPlanner.Presentation.Views.Shared" %>


<% if (!Model.IsSub)
   { %>
	<div class="courses-control yui-skin-sam" id="<%= Model.Id %>">
<% } %>


<% if (Model.Mode == CoursesControlMode.SELECT)
   { %>
		<div class="courses-selection">
		<% var vSelectedCourseIds = new List<string>(); %>
			<span class="select-courses link" onclick="gCoursesControlCtrl.onSelectCoursesClick(this)">
				<%= Tr("Select/Hide") %>
			</span>
			<div class="courses">
			<% foreach (var vCourse in Model.Courses)
				{ %>
					<% 
					var vChecked = false;
					if (Model.SelectedCourses.Contains(vCourse))
					{ 
						vSelectedCourseIds.Add(vCourse.EntityId.ToString());
						vChecked = true;
					}
					%>
					<div class="course left right-indented">
						<%= Html.CheckBox(Model.Id + "CourseCheck" + vCourse.EntityId, vChecked, new { value = vCourse.EntityId, onclick = "gCoursesControlCtrl.onCourseCheckClick(this)" }) %>
						<%= Html.Label(Model.Id + "CourseCheck" + vCourse.EntityId, vCourse.ShortName) %>
					</div>
				<% } %>
				<%= Html.ClearBreak() %>
			</div>
			<%= Html.Hidden(Model.SelectedCoursesFieldName, string.Join(",", vSelectedCourseIds.ToArray())) %>
		</div>
   <% }
   else
   { %>
		<div class="courses-list list left-padded">
		<% foreach (var vCourse in Model.Courses)
			{ %>
				<%
					var vPrereqs = new List<string>();
					var vCommonTerms = new List<string>();

					foreach (var vCrse in vCourse.Prerequisites.ToList())
					{
						vPrereqs.Add(Html.Encode(vCrse.ShortName));
					}
					foreach (var vTerm in vCourse.CommonlyOfferedInTerms.ToList())
					{
						vCommonTerms.Add(Html.Encode(vTerm.Name));
					}
				 %>
				<div class="course list-item top-padded bottom-separator" 
						cEditFormUrl="<%= Url.Action("CourseForm", "Controls", new { pScenario = CourseFormScenario.EDIT, pCourseId = vCourse.EntityId }) %>" 
						cDeleteUrl="<%= Url.Action("Delete", "Courses", new { pId = vCourse.EntityId }) %>">
					<div class="course-header list-item-header">
						<h3 class="left">
							<%= Html.Encode(vCourse.FullName)%>
						</h3>
						<%= WidgetHelper.ActionsContextMenu(Model.Id + "CourseMenu" + vCourse.EntityId.ToString(), "gCoursesControlCtrl.onCourseMenuClick", ContextMenuActions, ContextMenuIcons)%>
						<%= Html.ClearBreak() %>
					</div>
					<div class="course-body rows-wrapper">
						<div class="row">
							<div class="cell label">
								<%= Html.Label("", Html.Encode(Tr(Labels.Get("Credits", "Course"))))%>
							</div>
							<div class="cell">
								<%= vCourse.Credits%>
							</div>
						</div>
						<div class="row">
							<div class="cell label">
								<%= Html.Label("", Html.Encode(Tr(Labels.Get("Prerequisites", "Course"))))%>
							</div>
							<div class="cell">
								<%= string.Join(", ", vPrereqs.ToArray())%>
							</div>
						</div>
						<div class="row">
							<div class="cell label">
								<%= Html.Label("", Html.Encode(Tr(Labels.Get("CommonlyOfferedInTerms", "Course"))))%>
							</div>
							<div class="cell">
								<%= string.Join(", ", vCommonTerms.ToArray())%>
							</div>
						</div>
					</div>
				</div>
				<% } %>
		</div>
		<script type="text/javascript">
			gCoursesControlCtrl.messages.confirmDelete = '<%= SecurityHelper.Escape(Tr("Are you sure you want to delete this course? Dependants will also be deleted!")) %>';
			gDomReadyQueue.push('gCoursesControlCtrl.initList("<%= Model.Id %>");');
		</script>
<% } %>

<% if (!Model.IsSub)
   { %>
		</div>
<% } %>